package com.example.controller;

import com.example.nio.message.Request;
import com.example.nio.message.Response;
import com.example.nio.tranport.mina.factory.MinaClientFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.UUID;

@RestController
public class TestController {

    @Resource
    private MinaClientFactory minaClientFactory;

    /***
     * 异步推送，只返回推送结果，不管执行结果信息
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "sendAsyncRequest")
    public String sendAsyncRequest() throws Exception {
        String uuid = UUID.randomUUID().toString();
        Request request = new Request();
        request.setData(uuid);
        this.minaClientFactory.sendAsyncRequest(request);
        return uuid;
    }

    /***
     * 同步推送数据立马返回结果
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "sendSynRequest")
    public Response sendSynRequest() throws Exception {
        String uuid = UUID.randomUUID().toString();
        Request request = new Request();
        request.setData(uuid);
        return minaClientFactory.sendSynRequest(request);
    }
}
